<?php

namespace App\Http\Admin\Services\Manu;

use App\Exceptions\InvalidRequestException;
use App\Http\Models\Manu;
use App\Http\Models\Order;
use App\Http\Services\BaseService;
use App\Lib\PHPExcel\ExcelHandle;
use Illuminate\Support\Facades\DB;

class ManuService extends BaseService
{
    public function store($attributes = [])
    {
        if(empty($attributes)){
            throw new InvalidRequestException('参数错误 不能为空');
        }
        if(!is_array($attributes)){
            $attributes = json_decode($attributes,true);
        }

        if(!empty($attributes)){
            if(!empty($attributes['manu_no'])){
                $tmp = [
                    'manu_no' => $attributes['manu_no'],
                    'manu_name' => $attributes['manu_name'],
                    'goods_words' => $attributes['goods_words'],
                    'address' => $attributes['address'],
                    'phone' => $attributes['phone'],
                    'manu_type' => $attributes['manu_type'],
                    'charge_person' => $attributes['charge_person'],
                    'issue' => $attributes['issue'],
                    'sample' => $attributes['sample'],
                    'comp_oper' => $attributes['comp_oper'],
                    'group' => $attributes['group']
                ];
                //因为数量不多 所以直接循环判断
                if($attributes['type'] == 'edit'){

                    Manu::where('manu_no',$attributes['origin_manu_no'])
                        ->where('manu_name',$attributes['origin_manu_name'])
                        ->update($tmp);
                }else{
                    Manu::create($tmp);
                }
            }
        }

        return true;
    }
}